package com.yf.springboot.completablefuture;

import com.yf.springboot.util.FakeUtil;

import java.util.concurrent.CompletableFuture;

public class ThenCompose {
    public static void main(String[] args) {
        FakeUtil.printTimeAndThread("小白进入餐厅");
        FakeUtil.printTimeAndThread("小白点了 蕃茄炒蛋 + 一碗米饭");

        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
            FakeUtil.printTimeAndThread("厨师炒菜");
            FakeUtil.sleepMillis(2000);
            return "蕃茄炒蛋";
        }).thenCompose(dish -> CompletableFuture.supplyAsync(() -> {
            FakeUtil.printTimeAndThread("服务员打饭");
            FakeUtil.sleepMillis(1000);
            return dish + "米饭";
        }));

        FakeUtil.printTimeAndThread("小白开始打王者");
        FakeUtil.printTimeAndThread(String.format("服务员端上%s, 小白停止打王者，开始吃饭", cf1.join()));
    }
}
